import { defineStore } from 'pinia';
import { store } from "store2";
import _ from 'lodash';

const useWebsiteStore = defineStore('websiteStore', {
    state() {
        return {
            websites: [],
            name: 'lisi'
        }
    },
    actions: {
        add(item) {
            if(! _.find(this.websites, item)){
                this.websites.unshift(item)
                // store('websites',this.websites)
            }else{
                console.log('此网站已经添加');
                myApi.alert('此网站已经添加')
            }
            
        },

        init() {
            // this.websites = store.get('websites') || []
        },

        deleteItem(url) {
            let index = _.findIndex(this.websites, url)
            this.websites.splice(index,1)
            // store('websites',this.websites)
        },

        rename(nm) {
            this.name = nm
            console.log(nm);
        }
    }
})

export default useWebsiteStore